﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using cwtrock.model;
using cwtrock.util;
using cwtrock.service.impl;

namespace cwtrock.view
{
    public partial class UserPwdModFrm : Form
    {

        private SysUsrServiceImpl usrService = new SysUsrServiceImpl();

        public UserPwdModFrm()
        {
            InitializeComponent();
        }

        #region 单体模式
        //单体模式
        private static UserPwdModFrm frm = null;
        /// <summary>
        /// 单体模式
        /// </summary>
        /// <returns></returns>
        public static UserPwdModFrm getInstance()
        {
            if (frm == null)
            {
                frm = new UserPwdModFrm();
            }

            return frm;
        }
        #endregion

        private void UserPwdModFrm_Load(object sender, EventArgs e)
        {
            this.userId.Text = AppContextProvider.instance.LogUser.Usrid;
            this.userId.Enabled = false;
            this.usrName.Text = AppContextProvider.instance.LogUser.Usrname;
            this.pwd.Text = AppContextProvider.instance.LogUser.Usrpwd;


        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            string pwdTxt = this.pwd.Text;
            string usrName = this.usrName.Text;
            bool b = SimpleTool.validaing(this.errorProviderPwd,this.pwd,5, "密码") ;
            if (!b)
            {
                MessageBox.Show("密码长度不能大于5位", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            bool bName = SimpleTool.validaing(this.errorProviderName, this.usrName, 15, "姓名");
            if (!bName)
            {
                MessageBox.Show("姓名长度不能大于15位", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            usrService.modUserPwd(AppContextProvider.instance.LogUser.Usrid, pwdTxt,usrName);
            this.Hide();
        }

        private void btnConcel_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

    }
}
